package com.sfac.day03.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.day03.modules.account.entity.Resource;
import com.sfac.day03.modules.account.service.ResourceService;
import com.sfac.day03.modules.common.entity.ResultEntity;
import com.sfac.day03.modules.common.entity.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;
    @PostMapping(value = "/resource",consumes = "application/json")
    ResultEntity<Resource> insertResource(@RequestBody Resource resource){
      return resourceService.insertResource(resource);
    }
    @PutMapping(value = "/resource",consumes = "application/json")
    ResultEntity<Resource> updateResource(@RequestBody Resource resource){
      return resourceService.updateResource(resource);
    }
    @DeleteMapping("/resource/{id}")
    ResultEntity<Object> deleteResourceById(@PathVariable int id){
      return resourceService.deleteResourceById(id);
    }
    @GetMapping("/resource/{id}")
    Resource getResourceById(@PathVariable int id){
      return resourceService.getResourceById(id);
    }
    @GetMapping("/resources/{roleId}")
    List<Resource> getResourcesByRoleId(@PathVariable int roleId){
      return resourceService.getResourcesByRoleId(roleId);
    }
    @PostMapping(value = "/resources",consumes = "application/json")
    PageInfo<Resource> getResourcesBySearchBean(@RequestBody SearchBean searchBean){
        return resourceService.getResourcesBySearchBean(searchBean);
    }
}
